public class EnumTest {
    public static void main(String[] args) {
        //String name() 获取枚举项的名称
        String name = Enum.Monday.name();
        System.out.println(name);

        //int ordinal() 返回枚举项在枚举类中的索引值
        int index1 = Enum.Monday.ordinal();
        int index2 = Enum.Tuesday.ordinal();
        int index3 = Enum.Wednesday.ordinal();
        int index4 = Enum.Thursday.ordinal();
        int index5 = Enum.Friday.ordinal();
        int index6 = Enum.Saturday.ordinal();
        int index7 = Enum.Sunday.ordinal();
        System.out.println(index1);
        System.out.println(index2);
        System.out.println(index3);
        System.out.println(index4);
        System.out.println(index5);
        System.out.println(index6);
        System.out.println(index7);

        //int compareTo(E o) 比较两个枚举项，返回的是索引值的差值
        int i = Enum.Sunday.compareTo(Enum.Monday);
        System.out.println(i);

        //String toString()   返回枚举常量的名称
        String s = Enum.Monday.toString();
        System.out.println(s);

        //static <T> T valueOf(Class<T> type,String name)
        //       获取指定枚举类中的指定名称的枚举值
        Enum sunday = Enum.valueOf(Enum.class, "Sunday");
        System.out.println(sunday);

        //values()       获得所有的枚举项
        Enum[] values = Enum.values();
        for (Enum value : values) {
            System.out.println(value);
        }
    }
}
